﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using System.Xml.Serialization;

namespace ViewMaker.Core.Controls
{
    /// <summary>
    /// 日付選択Viewコントロール
    /// </summary>
    public class DatePickerViewControl : HeaderViewControl
    {

        /// <summary>
        /// プロパティ定数
        /// </summary>
        public new class Properties : HeaderViewControl.Properties
        {
            public const string SelectedDateFormat = "SelectedDateFormat";
        }

        /// <summary>
        /// 選択した日時のフォーマット
        /// </summary>
        [View(ViewControlType.ComboBox)]
        [ViewProperty(ComboBoxViewControl.Properties.ItemsSource, "SelectedDateFormatList")]
        public string SelectedDateFormat { get; set; }

        [Browsable(false)]
        [XmlIgnore]
        public string[] SelectedDateFormatList { get { return new string[] { "Short", "Long" }; } }

        public DatePickerViewControl()
        {
            ControlType = ViewControlType.DatePicker;
        }

        /// <summary>
        /// Xamlを生成する
        /// </summary>
        /// <param name="parent"></param>
        /// <returns></returns>
        public override List<XamlNode> CreateXaml(XamlNode parent)
        {
            var list = base.CreateXaml(parent);
#if !SILVERLIGHT
            var node = parent.CreateElement("DatePicker");
            var style = CreateStyle(node, "DatePickerTextBox");
            if (style != null) node.AddElement("DatePicker.Resources").AppendChild(style);
#else
            var node = parent.CreateElement("sdk", "http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk", "DatePicker");
#endif
            SetBindingAttribute(node, "SelectedDate", Item.BindPath, Item.IsOneWay);
            if (!string.IsNullOrEmpty(SelectedDateFormat)) node.SetAttribute("SelectedDateFormat", SelectedDateFormat);
            ApplyBaseProperty(node);
            list.Add(node);
            return list;

        }

    }
}
